﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TripleQueue
{
    public enum Priority { high = 0, med = 1, low = 2 } 

    public class QueueWithThreeCategories
    {
        private Queue<Person>[] queues = new Queue<Person>[3];

        private Person servicing = null;

        public QueueWithThreeCategories()
        {
            for (int i = 0; i < queues.Count(); i++)
            {
                queues[i] = new Queue<Person>();
            }
        }

        public void Draw(Graphics g)
        {
            Pen pen = new Pen(Color.Black);
            Brush brush = new SolidBrush(Color.Black);
            Brush pBrush = new SolidBrush(Color.Green);
            Font font = new Font(FontFamily.GenericSansSerif, 12);
            g.DrawRectangle(pen, 20, 50, 100, 500);
            g.DrawRectangle(pen, 140, 50, 100, 500);
            g.DrawRectangle(pen, 260, 50, 100, 500);
            g.DrawRectangle(pen, 380, 50, 100, 100);
            g.DrawString("High", font, brush, 20, 30);
            g.DrawString("Med", font, brush, 140, 30);
            g.DrawString("Low", font, brush, 260, 30);
            g.DrawString("Serviced", font, brush, 380, 30);
            for (int i = 0; i < queues.Count(); i++)
            {
                for (int j = 0; j < queues[i].Count; j++)
                {
                    g.FillRectangle(pBrush, i * 120 + 30, j * 90 + 60, 80, 80);
                    g.DrawString(queues[i].ElementAt(j).Name, font, brush, i * 120 + 30, j * 90 + 60);
                }
            }
            if (servicing != null)
            {
                g.FillRectangle(pBrush, 390, 60, 80, 80);
                g.DrawString(servicing.Name, font, brush, 390, 60); 
            }
        }

        public void AddPerson(Person person, Priority priority)
        {
            queues[(int)priority].Enqueue(person);
        }

        public void ServicePerson()
        {
            bool newServicing = false;
            for (int i = 0; i < queues.Count(); i++)
            {
                if (queues[i].Count != 0)
                {
                    servicing = queues[i].Dequeue();
                    newServicing = true;
                    break;
                }
            }
            if (!newServicing)
                servicing = null;
        }
    }
}
